home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
kermit.columbia.edu
/
kermit.columbia.edu.tar
/
kermit.columbia.edu
/
newsgroups
/
misc.19981211-19990422
/
000447_news@watsun.cc.columbia.edu _Mon Apr 19 14:22:13 1999.msg
< prev
next >
Wrap
Internet Message Format
|
1999-04-21
|
6KB
Return-Path: <news@watsun.cc.columbia.edu>
Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.59.30])
by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id OAA03902
for <kermit.misc@watsun.cc.columbia.edu>; Mon, 19 Apr 1999 14:22:12 -0400 (EDT)
Received: (from news@localhost)
by newsmaster.cc.columbia.edu (8.8.5/8.8.5) id OAA13809
for kermit.misc@watsun.cc.columbia.edu; Mon, 19 Apr 1999 14:04:24 -0400 (EDT)
X-Authentication-Warning: newsmaster.cc.columbia.edu: news set sender to <news> using -f
From: fdc@watsun.cc.columbia.edu (Frank da Cruz)
Subject: Re: Help on shell script doing ftp
Date: 19 Apr 1999 18:04:19 GMT
Organization: Columbia University
Message-ID: <7ffr73$dfe$1@newsmaster.cc.columbia.edu>
To: kermit.misc@watsun.cc.columbia.edu
In article <7ff65g$f9d$1@news1.global-one.dk>,
Jan Fjeldmark <jfj.it@dsg.dk> wrote:
: Stefan A. Deutscher wrote:
: >On Fri, 9 Apr 1999 19:05:20 -0500, steve VanArsdale
: ><first.consultant@picksys.com> wrote:
: >>i am looking for a workaround for ftp in an batch AIX shell script.
: >>
: >>Specifically, we need the script to open an ftp session to a remote AIX
: >>system with both the login and the password, check for the existence of
: >>a file, and if not present, put the file on the remote directory. If
: >>the file is present on the remote directory the script must record an
: >>error and exit without putting the file.
: >>
: >>ftp always prompts for the password, and we can't figure out how to
: >>make the script conditional on the presence of the file in the remote
: >>directory.
: >
: >Unless it _has_ to be ftp/ftpd you could try a small kermit script.
: >That's at least what I'd do. Cheer, Stefan
:
: Like telnet, ftp uses .netrc to login to foreign hosts. Put this line in
: .netrc:
:
: machine myhost login myname password mypw
:
: Now ftp won't prompt for userid or password.
:
: To test for presence of a specific file on the remote host and act
: correspondingly, you wil have to run ftp several times and analyse the out
: using grep or similar.
:
Or as Stephan suggests, you can use Kermit instead of FTP.
: >>Specifically, we need the script to open an ftp session to a remote AIX
: >>system with both the login and the password, check for the existence of
: >>a file, and if not present, put the file on the remote directory. If
: >>the file is present on the remote directory the script must record an
: >>error and exit without putting the file.
:
Here's an illustration using C-Kermit 7.0 Beta.06:
http://www.columbia.edu/kermit/ck70.html
--(cut here)--
#/usr/local/bin/kermit +
define fatal { hangup, exit 1 \%1 }
set network type tcp/ip
if fail exit 1 { Sorry, this version of C-Kermit does not support TCP/IP.}
while not def \%1 { ; If hostname/address not supplied
ask \%1 { Host: } ; prompt for one until we get it.
if > \fsplit(\%1) 1 { ; Allow only one "word" here.
echo Just the address please. ; E.g. no TCP port number.
undef \%1
}
}
if not def \%2 { ; If username not supplied
ask \%2 { User [\v(user)]: } ; Prompt for one, but default
if not def \%2 assign \%2 \v(user) ; to local user ID.
}
echo Connecting to \%1 as user \%2...
set host \%1 23
if fail exit 1 Can't open Telnet connection to \%1.
; Prompt for password if necessary only after connection is made
; (because there's no point in asking for it if the connection failed).
while not defined \%3 {
askq \%3 { Password for \%2 at \%1: }
}
set input echo off ; Don't echo scripted interactions.
; Get any of several possible login prompts:
minput 20 login: Username: Password: {Password for \%2:}
if fail exit 1 Timed out waiting for initial prompt: \v(inwait) sec.
if ( = \v(minput) 1 || = \v(minput) 2 ) {
lineout \%2 ; User ID required - send it.
minput 10 Password: {Password for \%2:}
if fail exit 1 Timed out waiting for Password prompt: \v(inwait) sec.
}
lineout \%3 ; Send password
undef \%3 ; Erase password from memory
set exit on-disconnect on ; Exit automatically if connection broken.
; Start Kermit server on the remote end
;
lineout kermit -x
; From this point all commands are issued from the client.
;
; Let's say the directory in question is /tmp/test
; and the filename is foo. Of course you could use variables here.
;
log transactions ; Keep a record of file transfers
remote cd /tmp/test
if fail fatal {Can't CD to /tmp/test}
remote query files(foo)
if = \v(query) 0 {
writeln transactions File "foo" already exists on server.
echo File "foo" already exists on server - quitting...
exit 0
}
send foo
if fail fatal {Upload failed}
bye
exit 0 Upload succeeded
---(cut here)---
Save this file under whatever name you want, give it execute permission,
and then run it as if it were a shell script. The host, username, and
password can be given as arguments on the command line; if they are not
given, the script prompts you for them.
You can simplify the upload part considerably by telling the server to
"set file collision discard" -- meaning if the client tries to send it a
file whose name is the same as a file already present at the server, the
server rejects it. Other options include "set file collision update",
meaning to accept the incoming file only if it is newer than the existing one.
- Frank